<?php

/**
 * This is the model class for table "zy_award_address".
 *
 * The followings are the available columns in table 'zy_award_address':
 * @property integer $address_id
 * @property string $company_name
 * @property string $area
 * @property string $address
 * @property integer $belong
 * @property string $crate_time
 * @property string $crate_user
 * @property string $update_time
 * @property string $update_user
 */
class AwardAddress extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return AwardAddress the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'zy_award_address';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('company_name,area,address','required'),
			array('belong', 'numerical', 'integerOnly'=>true),
			array('company_name', 'length', 'max'=>300),
			array('area', 'length', 'max'=>200),
			array('address', 'length', 'max'=>500),
			array('crate_user, update_user', 'length', 'max'=>50),
			array('crate_time, update_time', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('address_id, company_name, area, address, belong, crate_time, crate_user, update_time, update_user', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'address_id' => Yii::t('base','Address ID'),
			'company_name' => Yii::t('base','Company Name'),
			'area' => Yii::t('base','Area'),
			'address' => Yii::t('base','Specific address'),
			'belong' => Yii::t('base','Belong'),
			'crate_time' => 'Crate Time',
			'crate_user' => 'Crate User',
			'update_time' => 'Update Time',
			'update_user' => 'Update User',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.
		$userID = yii::app()->user->id;
		$criteria=new CDbCriteria;

		$criteria->compare('address_id',$this->address_id);
		$criteria->compare('company_name',$this->company_name,true);
		$criteria->compare('area',$this->area,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('belong',$userID);
		$criteria->compare('crate_time',$this->crate_time,true);
		$criteria->compare('crate_user',$this->crate_user,true);
		$criteria->compare('update_time',$this->update_time,true);
		$criteria->compare('update_user',$this->update_user,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}